<template>
  <div>
    <h1>{{ id ? "修改" : "新建" }}区域</h1>
    <el-form label-width="50px" @submit.native.prevent="save">
      <el-form-item label="区域" style="margin-top: 30px">
        <el-input
          v-model="model.name"
          style="width: 200px"
          placeholder="请输入区域名称"
        ></el-input>
      </el-form-item>
            <el-form-item label="数量" style="margin-top: 30px;">
        <el-input
          v-model="model.number"
          style="width: 200px"
          placeholder="请输入最大停车数量"
        ></el-input>
      </el-form-item>
      <el-button type="primary" native-type="submit">保存</el-button>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      model: {},
      // parents: [],
    };
  },
  props: {
    id: {},
  },
  methods: {
    async save() {
      let res;
      if (this.id) {
        res = await this.$http.put(`rest/categories/${this.id}`, this.model);
      } else {
        this.model.count = 0
        this.model.counts = this.model.number
        res = await this.$http.post("rest/categories", this.model);
      }
      this.$router.push("/categories/list");
      this.$message({
        type: "success",
        message: "保存成功了",
      });
    },
    async fetch() {
      const res = await this.$http.get(`rest/categories/${this.id}`);
      this.model = res.data;
    },
    // async parentsfetch() {
    //   const res = await this.$http.get(`rest/categories`);
    //   this.parents = res.data;
    // },
  },
  created() {
    // this.parentsfetch();
    this.id && this.fetch();
  },
};
</script>

<style scoped>
</style>
